class Solution {//leetcode2331——计算布尔二叉树的值
public:
    bool dfs(TreeNode* root){//判断子树是true还是false
        if(root==nullptr) return true;
        if(root->val==1) return true;
        if(root->val==0) return false;

        bool left=dfs(root->left);
        bool right=dfs(root->right);
        
        return root->val==2?left|right:left&&right;//后序遍历
    }

    bool evaluateTree(TreeNode* root) {
        return dfs(root);    
    }
};